import { getAreaObj } from '@/utils/util'
import { getStore } from '@/utils/store'
const userInfo = getStore('userInfo') || {}
let creditCode = userInfo.organizationId || ''
creditCode = creditCode == 1 ? undefined : creditCode

export const searchConfig = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	labelWidth: '80px',
	column: [
		{
			prop: 'equipmentNo',
			label: '设备编号',
			span: 8,
		},
		{
			label: '维护时间',
			prop: 'maintainTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '维护人',
			prop: 'maintainUserId',
			propName: 'maintainUser',
			type: 'remoteSelect',
			api: 'sys_user_querypage',
			filterKey: 'userId',
			filterLabel: 'realName',
			paramsObj: {
				classifyId: 4,
				organizationId: creditCode,
			},
			span: 8,
		},

		{
			label: '维护状态',
			prop: 'maintainState',
			type: 'select',
			dicData: [
				{ label: '正常', value: 0 },
				{ label: '异常', value: 1 },
				{ label: '已解决', value: 2 },
			],
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '设备编号', prop: 'equipmentNo' },
		{ label: '维护时间', prop: 'maintainTime' },
		{ label: '维护人', prop: 'maintainUser' },

		{
			label: '维护状态',
			prop: 'maintainState',
			custome: 'tag',
			dicData: [
				{ label: '正常', value: 0, type: 'success' },
				{ label: '异常', value: 1, type: 'danger' },
				{ label: '已解决', value: 2, type: 'info' },
			],
		},
		{ label: '维护图片', custome: 'file', prop: 'maintainPicture' },
		{ label: '备注', prop: 'abnormalRemark' },
	],
}

export const api = {
	index: 'dotEquipmentMaintainRecord_page',
}
export const baseConfig = {
	pageName: '智能设备维护管理',
	dictcodes: ['EQUIPMENT_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'maintainTime',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	tableConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			if (form.maintainState == 0) {
				form.abnormalStatus = 0
			} else if (form.maintainState == 1) {
				form.abnormalStatus = 1
			}
			const params = {
				...form,
			}
			resolve(params)
		})
	},
}
